import React from 'react';
import Child from './Child'

class Parent extends React.Component {
    handleChild = ()=> {
        this.$Child.childMethod();    // this上就有了子组件
    }
    render() {
        return (
            <div>
                <Child onRef={(ref)=> {this.$Child=ref}} />
                <button onClick={this.handleChild}>调用子组件方法</button>
            </div>
        )
    }
}

export default Parent;
